/**
 * Beaver - Zend/Ext.Direct framework
 *
 * @license     http://www.gnu.org/licenses/gpl-2.0.txt
 * @author      Mihály Kuprivecz <mkuprivecz@gmail.com>
 * @namespace   Beaver.Modules.User
 */
Ext.ns('Beaver.Modules.General');

Beaver.Modules.General.Store = Ext.extend(Ext.data.DirectStore, {
    constructor: function(config){
    
        config = config ||
        {};
        config.api = config.api ||
        {};
        
        Ext.applyIf(config.api, {
            create: Beaver.Remote[config.controllerName].create,
            read: Beaver.Remote[config.controllerName].read,
            update: Beaver.Remote[config.controllerName].update,
            destroy: Beaver.Remote[config.controllerName].destroy
        });
        
        Ext.applyIf(config, {
            root: 'data',
            idProperty: 'id',
            totalProperty: 'total',
            successProperty: 'success',
            messageProperty: 'message',
            autoLoad: true,
            autoSave: true,
            writer: new Ext.data.JsonWriter({
                writeAllFields: true,
                encode: false
            }),
            autoDestroy: true
        });
        
        Beaver.Modules.General.Store.superclass.constructor.apply(this, [config]);
    }
});

Ext.reg('beaverstore', Beaver.Modules.General.Store);

Beaver.Modules.General.Grid = Ext.extend(Ext.grid.EditorGridPanel, {

    initComponent: function(){
    
        var config = {
            width: '100%',
            autoDestroy: true,
            border: false,
            viewConfig: {
                forceFit: true
            },
			selModel: new Ext.grid.RowSelectionModel()
        };
        
        Ext.apply(this, config);
        Ext.apply(this.initialConfig, config);
        
        Beaver.Modules.General.Grid.superclass.initComponent.apply(this, arguments);
        
    },
    onRender: function(){
        Beaver.Modules.General.Grid.superclass.onRender.apply(this, arguments);
    }
    
});

Ext.reg('beavergrid', Beaver.Modules.General.Grid);



Beaver.Modules.General.RowEditor = Ext.extend(Ext.ux.grid.RowEditor, {
	//deleteText: 'Törlés',
	saveText: 'Mentés',
	cancelText: 'Mégsem',
	initComponent: function(){

		var config = {};

		Ext.apply(this, config);
		Ext.apply(this.initialConfig, config);

		Beaver.Modules.General.RowEditor.superclass.initComponent.apply(this, arguments);

	},
	
    /*onRender: function(){
		Ext.ux.grid.RowEditor.superclass.onRender.apply(this, arguments);
		this.el.swallowEvent(['keydown', 'keyup', 'keypress']);
		this.btns = new Ext.Panel({
			baseCls: 'x-plain',
			cls: 'x-btns',
			elements: 'body',
			layout: 'table',
			width: (this.minButtonWidth * 3) + (this.frameWidth * 2) + (this.buttonPad * 6), // width must be specified for IE
			items: [{
				ref: 'saveBtn',
				itemId: 'saveBtn',
				xtype: 'button',
				text: this.saveText,
				width: this.minButtonWidth,
				handler: this.stopEditing.createDelegate(this, [true])
			}, {
				xtype: 'button',
				text: this.cancelText,
				width: this.minButtonWidth,
				handler: this.stopEditing.createDelegate(this, [false])
			}, {
				xtype: 'button',
				text: this.deleteText,
				width: this.minButtonWidth,
				handler: this.deleteRow.createDelegate(this)
			}]
		});
		this.btns.render(this.bwrap);
    },*/
	
	/*deleteRow: function(){
		Ext.Msg.confirm('Törélés', 'Biztosan törölni szeretné?', function( answer ){
			if (answer == "yes")
			{
				this.grid.getStore().remove(this.record);
			}
		},this);
	}*/
});

Ext.reg('beaverroweditor', Beaver.Modules.General.RowEditor);
